package com.csyf.manager.controller;

import com.csyf.manager.channel.base.BaseReturn;
import com.csyf.manager.entity.SysWithdrawalRecord;
import com.csyf.manager.exception.ApiValidateException;
import com.csyf.manager.service.SysWithdrawalRecordService;
import com.csyf.manager.utils.ResultEntity;
import com.csyf.manager.utils.ResultUtli;
import com.csyf.manager.utils.page.JqGridVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @Author: casper
 * @Description: 提现记录Controller
 * @Date: Created in 2018/10/27 17:39
 */
@Controller
@RequestMapping(value = "boss/withdrawal")
public class SysWithdrawalRecordController {

    @Autowired
    private SysWithdrawalRecordService sysWithdrawalRecordService;

    @GetMapping(value = "view/{pageName}")
    public String viewPage(@PathVariable(value = "pageName") String pagename) {
        return "boss/" + pagename;
    }

    @ResponseBody
    @PostMapping(value = "withdrawalRecordDataList")
    public JqGridVo withdrawalRecordDataList(SysWithdrawalRecord vo, Integer rows, Integer page) {
        return sysWithdrawalRecordService.querydata(vo, rows, page);
    }

    @ResponseBody
    @PostMapping(value = "withdrawMoney")
    public ResultEntity withdrawMoney(Long accountId, BigDecimal withdrawMoney) {
        try {
            if (null != accountId) {
                sysWithdrawalRecordService.withdrawalMoney(accountId, withdrawMoney);
                return ResultUtli.DEFAULT_SUCCESS("提现成功！", null);
            }
            return ResultUtli.ERRO(10, "提现失败！", null);
        }catch (ApiValidateException e) {
            return ResultUtli.ERRO(10, e.getMessage(), null);
        }catch (Exception e) {
            e.printStackTrace();
            return ResultUtli.ERRO(10, e.getMessage(), null);
        }
    }



}
